package core;

import resources.core.PreconditionsHelper;
import core.enums.Reports;
import core.exceptions.ResultFailureException;

/**
 * Description : Functional Test Script
 * 
 * @author angel.tsvetkov
 */
public class Preconditions extends PreconditionsHelper
{
    /**
     * Script Name : <b>Preconditions</b> Generated : <b>22.06.2010 14:06:33</b> Description : Functional Test Script
     * Original Host : WinNT Version 5.1 Build 2600 (S)
     * 
     * @since 2010/06/22
     * @author angel.tsvetkov
     */ 
	
    public static boolean precondition(String username, String password, Reports report, String param)
    {
        boolean result = false;
        preconditionReady = false;
            
        PropertiesContainer propContainer = PropertiesContainer.getInstance();
        
        String user = (username != null)?(username):propContainer.getUsername();
        String pass = (password != null)?(password):propContainer.getPassword();
        
        String reportURL = report.getURL();
        
        reportURL = reportURL.replace("%PARAM%", param);

        if (LoginTasks.openBrowser(reportURL))
        {
        	TimeWait(3);
        	if (LoginTasks.loginUser(user, pass, report.isCognos()))
            {    		
                result = true;
            }
            else
            {
            	setErrorComment("Loging procedure fail!");
            }
        }
        else
        {
        	setErrorComment("The browser cannot be started!");
        }

        preconditionReady = true;
        return result;
    }
    
    
    //COGNOS
    public static boolean globalPreconditionCognos(String username, String password, Reports reportName)
    {
    	return precondition(username, password, reportName, "");
    }
    public static boolean globalPreconditionCognos(Reports reportName)
    {
    	return globalPreconditionCognos(null, null, reportName);
    }
    
    public static boolean globalPreconditionCognosWithParam(String username, String password, Reports reportName, String param)
    {
    	return precondition(username, password, reportName, param);
    }
    
    public static boolean globalPreconditionCognosWithParam(Reports reportName, String param)
    {
    	return globalPreconditionCognosWithParam(null, null, reportName, param);
    }
    
    
    //WEB SPHERE
    public static boolean globalPreconditionWebSpehere(String username, String password, Reports reportName)
    {
    	return precondition(username, password, reportName, "");
    }
    
    public static boolean globalPreconditionWebSpehere(Reports reportName)
    {
    	return globalPreconditionWebSpehere(null, null, reportName);
    }
     
    public static boolean globalPreconditionWebSpehereWithParam(String username, String password, Reports reportName, String param)
    {
    	return precondition(username, password, reportName, param);
    }
    
    public static boolean globalPreconditionWebSpehereWithParam(Reports reportName, String param)
    {
    	return globalPreconditionWebSpehereWithParam(null, null, reportName, param);
    }
}
